#ifndef C_ALGORITHM_BST_TREE_H
#define C_ALGORITHM_BST_TREE_H

#include <stdbool.h>
#include <stddef.h>

// 不完整类型,bst树指针, 隐藏树结构定义
typedef struct bst_t *btree;

// 不完整类型, bst树节点指针类型, 隐藏节点定义
typedef struct node_t *bst_node;

// 函数类型,获得结点的键值
typedef const void *get_key_func_t(const void *data);

// 排序比较函数
typedef int cmp_func_t(const void *key1, const void *key2);

btree bst_create(cmp_func_t *cmp, get_key_func_t *getKey);

void bst_clear(btree bst);

void bst_destory(btree bst);

bool bst_insert(btree bst, const void *data, size_t data_size);

bool bst_delete(btree bst, const void *key);

const void *bst_search(btree bst, const void *key);

int bst_in_order(btree bst, bool (*action)(void *data));

int bst_pre_order(btree bst, bool (*action)(void *data));

int bst_post_order(btree bst, bool (*action)(void *data));

#endif